/**
 * 给定数组A，问有多少对(Ai, Aj)拼起来是36的倍数
 * N在1000，直接枚举
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pii>;

int N;
vi A;

bool isok(int a, int b){
    int t = a;
    if(b == 10) t = t * 100 + b;
    else t = t * 10 + b;
    return 0 == t % 36;
}

int proc(){
    int ans = 0;
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            if(i == j) continue;
            if(isok(A[i], A[j])){
                ans += 1;
            }
        }
    }
    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1; 
    // cin >> nofkase;
    while(nofkase--){
        cin >> N;
        A.assign(N, {});
        for(auto & i : A) cin >> i;
        cout << proc() << "\n";
    }
    return 0;
}